#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int f[N];
struct Node {
  int a, b, c;
  bool operator<(const Node& o) const { return c < o.c; }
} a[N];
void init(int n) { rep(i, 1, n * 2) f[i] = i; }
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
bool same(int x, int y) {
  int fx = find(x), fy = find(y);
  return fx == fy;
}
void merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return;
  f[fy] = fx;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m) cin >> a[i].a >> a[i].b >> a[i].c;
  sort(a + 1, a + m + 1);
  init(n * 2);
  per(i, m, 1) {
    if (same(a[i].a, a[i].b)) {
      cout << a[i].c;
      return 0;
    }
    merge(a[i].a, n + a[i].b), merge(a[i].b, n + a[i].a);
  }
  cout << 0;
  return 0;
}